<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="评委会名称" prop="name">
      <el-input v-model="dataForm.name" placeholder="评委会名称"></el-input>
    </el-form-item>
    <el-form-item label="类型: 1:审查委员会, 2:评标委员会" prop="type">
      <el-input v-model="dataForm.type" placeholder="类型: 1:审查委员会, 2:评标委员会"></el-input>
    </el-form-item>
    <el-form-item label="组建评委会方式: 1:随机抽取, 2:手工抽取" prop="method">
      <el-input v-model="dataForm.method" placeholder="组建评委会方式: 1:随机抽取, 2:手工抽取"></el-input>
    </el-form-item>
    <el-form-item label="组建评委会方式: 1:随机抽取, 2:手工抽取" prop="noticeMethod">
      <el-input v-model="dataForm.noticeMethod" placeholder="组建评委会方式: 1:随机抽取, 2:手工抽取"></el-input>
    </el-form-item>
    <el-form-item label="评标专家人数" prop="expertNum">
      <el-input v-model="dataForm.expertNum" placeholder="评标专家人数"></el-input>
    </el-form-item>
    <el-form-item label="招标人代表人数" prop="biderNum">
      <el-input v-model="dataForm.biderNum" placeholder="招标人代表人数"></el-input>
    </el-form-item>
    <el-form-item label="评委会总人数" prop="juryNum">
      <el-input v-model="dataForm.juryNum" placeholder="评委会总人数"></el-input>
    </el-form-item>
    <el-form-item label="监抽人" prop="supervisor">
      <el-input v-model="dataForm.supervisor" placeholder="监抽人"></el-input>
    </el-form-item>
    <el-form-item label="评标时间" prop="evaluationTime">
      <el-input v-model="dataForm.evaluationTime" placeholder="评标时间"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="linker">
      <el-input v-model="dataForm.linker" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="linkMobile">
      <el-input v-model="dataForm.linkMobile" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input type="textarea" v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          name: '',
          type: '',
          method: '',
          noticeMethod: '',
          expertNum: '',
          biderNum: '',
          juryNum: '',
          supervisor: '',
          evaluationTime: '',
          linker: '',
          linkMobile: '',
          remark: '',
          createOn: '',
          createUserId: '',
          createBy: '',
          modifiedOn: '',
          modifiedUserId: '',
          modifiedBy: ''
        },
        dataRule: {
          name: [
            { required: true, message: '评委会名称不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '类型: 1:审查委员会, 2:评标委员会不能为空', trigger: 'blur' }
          ],
          method: [
            { required: true, message: '组建评委会方式: 1:随机抽取, 2:手工抽取不能为空', trigger: 'blur' }
          ],
          noticeMethod: [
            { required: true, message: '组建评委会方式: 1:随机抽取, 2:手工抽取不能为空', trigger: 'blur' }
          ],
          expertNum: [
            { required: true, message: '评标专家人数不能为空', trigger: 'blur' }
          ],
          biderNum: [
            { required: true, message: '招标人代表人数不能为空', trigger: 'blur' }
          ],
          juryNum: [
            { required: true, message: '评委会总人数不能为空', trigger: 'blur' }
          ],
          supervisor: [
            { required: true, message: '监抽人不能为空', trigger: 'blur' }
          ],
          evaluationTime: [
            { required: true, message: '评标时间不能为空', trigger: 'blur' }
          ],
          linker: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          linkMobile: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          createOn: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          modifiedOn: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          modifiedUserId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          modifiedBy: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/expert/expertgroup/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.name = data.expertGroup.name
                this.dataForm.type = data.expertGroup.type
                this.dataForm.method = data.expertGroup.method
                this.dataForm.noticeMethod = data.expertGroup.noticeMethod
                this.dataForm.expertNum = data.expertGroup.expertNum
                this.dataForm.biderNum = data.expertGroup.biderNum
                this.dataForm.juryNum = data.expertGroup.juryNum
                this.dataForm.supervisor = data.expertGroup.supervisor
                this.dataForm.evaluationTime = data.expertGroup.evaluationTime
                this.dataForm.linker = data.expertGroup.linker
                this.dataForm.linkMobile = data.expertGroup.linkMobile
                this.dataForm.remark = data.expertGroup.remark
                this.dataForm.createOn = data.expertGroup.createOn
                this.dataForm.createUserId = data.expertGroup.createUserId
                this.dataForm.createBy = data.expertGroup.createBy
                this.dataForm.modifiedOn = data.expertGroup.modifiedOn
                this.dataForm.modifiedUserId = data.expertGroup.modifiedUserId
                this.dataForm.modifiedBy = data.expertGroup.modifiedBy
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/expert/expertgroup/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'name': this.dataForm.name,
                'type': this.dataForm.type,
                'method': this.dataForm.method,
                'noticeMethod': this.dataForm.noticeMethod,
                'expertNum': this.dataForm.expertNum,
                'biderNum': this.dataForm.biderNum,
                'juryNum': this.dataForm.juryNum,
                'supervisor': this.dataForm.supervisor,
                'evaluationTime': this.dataForm.evaluationTime,
                'linker': this.dataForm.linker,
                'linkMobile': this.dataForm.linkMobile,
                'remark': this.dataForm.remark,
                'createOn': this.dataForm.createOn,
                'createUserId': this.dataForm.createUserId,
                'createBy': this.dataForm.createBy,
                'modifiedOn': this.dataForm.modifiedOn,
                'modifiedUserId': this.dataForm.modifiedUserId,
                'modifiedBy': this.dataForm.modifiedBy
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
